package com.hxk.ioText.byteIo.handleIo;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Date;

import com.hxk.ioText.bean.User;

public class ObjectIo {

	public static void main(String[] args) {
		ObjectInputStream ois = null;
		ObjectOutputStream oos = null;
		try {
			oos = new ObjectOutputStream(new FileOutputStream("d:/o.txt"));
			oos.writeInt(123);
			oos.writeDouble(0.123);
			oos.writeBoolean(true);
			oos.writeUTF("java 数据流");
			oos.writeChar('a');
			oos.writeObject(new Date());
			User u = new User(1, "张三", "男", 18);
			oos.writeObject(u);
			
			ois = new ObjectInputStream(new FileInputStream("d:/o.txt"));
			int n = ois.readInt();
			System.out.println(n);
			double d = ois.readDouble();
			System.out.println(d);
			boolean b = ois.readBoolean();
			System.out.println(b);
			String s = ois.readUTF();
			System.out.println(s);
			char c = ois.readChar();
			System.out.println(c);
			Date date = (Date) ois.readObject();
			System.out.println(date);
			User user = (User) ois.readObject();
			System.out.println(user);
		}catch (Exception e) {
			e.printStackTrace();
		}finally {
			try {
				if(ois != null) {
					ois.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			try {
				if(oos != null) {
					oos.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
	}

}
